
//
//  ZYNewsMessageController.m
//  优学荟管理系统
//
//  Created by edz on 2017/11/3.
//  Copyright © 2017年 星道三好. All rights reserved.
//

#import "ZYNewsMessageController.h"
#import "ZYNewsMessageCell.h"
#import "ZYNewsMessageModel.h"
#define kCell @"cell"

#import "ZYConmentDetailsController.h"
@interface ZYNewsMessageController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong)UITableView *tableView;
@property (nonatomic,strong) NSMutableArray *dataSource;
@property (nonatomic,assign) BOOL isTrue;
@property (nonatomic,assign) NSInteger page;

@end

@implementation ZYNewsMessageController
- (NSMutableArray *)dataSource {
    
    if (_dataSource == nil) {
        self.dataSource = [NSMutableArray array];
    }
    
    return _dataSource;
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
   
    self.title  = @"新消息";
    
    
//    UIBarButtonItem *liftItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"icon_back"] style:(UIBarButtonItemStyleDone) target:self action:@selector(liftItemAction)];
//    self.navigationItem.leftBarButtonItem = liftItem;
    
    
    [self setNetWork];
    [self setUpSuperView];
  
    
    
}


- (void)liftItemAction{
    
    if (self.popBalock) {
        self.popBalock();
    }
    
    
    [self.navigationController popViewControllerAnimated:YES];
    
    
    
}




- (void)setNetWork{
    
  //  http://192.168.0.113:8080/StarShine/ws/trainLesson.do?action=getCommentReplyByUid&pageNumber=1
    self.page = 1;
    NSString *url = [NSString stringWithFormat:@"trainLesson.do?action=getCommentReplyByUid&pageNumber=%ld",(long)self.page];
    
    
    
    
    NSLog(@"%@ %@",LLBaseURL(url),[AccountTool shareAccountTool].currentAccount.authCode);
    [SVProgressHUD setDefaultStyle:(SVProgressHUDStyleCustom)];
    [SVProgressHUD  setBackgroundColor:ColorRGB(4, 4, 4)];
    [SVProgressHUD setForegroundColor:[UIColor whiteColor]];
    [SVProgressHUD showWithStatus:LLLoading];
    [NetManager Get:LLBaseURLs(url) Auth:YES Params:nil Success:^(id Obj) {
        [SVProgressHUD dismiss];
        
        if ([[Obj valueForKey:@"code"]integerValue] == 1000) {
            NSDictionary *t = [Obj valueForKey:@"t"];
            
            NSArray *arr = [t valueForKey:@"dataList"];
            
            for (NSDictionary *dict in arr) {
                
                ZYNewsMessageModel *model = [ZYNewsMessageModel new];
                
                
                model.ID = [dict valueForKey:@"id"];
//
                
                [model setValuesForKeysWithDictionary:dict];
                
                
                [self.dataSource addObject:model];
                
            }
            
        }
        
        
        
        [self.tableView reloadData];
        [self.tableView.mj_header endRefreshing];
        [self.tableView.mj_footer endRefreshing];
        
        
        
        
    } Fail:^(NSError *Error) {
        [self.tableView.mj_footer endRefreshing];
        [self.tableView.mj_header endRefreshing];
        [SVProgressHUD dismiss];
    }];
    
    
    
}







- (void)setUpSuperView{
    
    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight - 64) style:(UITableViewStyleGrouped)];
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    [self.view addSubview:self.tableView];
    
    [self.tableView registerClass:[ZYNewsMessageCell  class] forCellReuseIdentifier:kCell];
    self.tableView.estimatedRowHeight = 200;
    self.tableView.contentInset = UIEdgeInsetsMake(-20,0,0, 0);
    //    self.automaticallyAdjustsScrollViewInsets = NO;
    self.tableView.tableFooterView = [UIView new];
    
    
    
    
    
}
#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    
    return self.dataSource.count;
}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    ZYNewsMessageCell *cell = [tableView dequeueReusableCellWithIdentifier:kCell forIndexPath:indexPath];
    


    if (self.dataSource.count > indexPath.row) {
    
        
        ZYNewsMessageModel *model = self.dataSource[indexPath.row];
        
        
        [cell assignByZYNewsMessageModel:model];
        
        
        
    }
    
    
    
    

    
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    ZYNewsMessageModel *model = [self.dataSource objectAtIndex:indexPath.row];
    
    
    
    ZYConmentDetailsController *vc = [ZYConmentDetailsController new];
    vc.commentId = [NSString stringWithFormat:@"%@",model.commentId];
    vc.uid= [NSString stringWithFormat:@"%@",[model.user valueForKey:@"uid"]];
    vc.petName = [NSString stringWithFormat:@"%@",[model.user valueForKey:@"petName"]];
    vc.ID = [NSString stringWithFormat:@"%@",model.ID];
    
    [self.navigationController pushViewController:vc animated:YES];
    
    
    
    
}

@end
